home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7636 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.7 KB  |  127 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Questions.
  5. Date: Sat, 24 Feb 1996 18:52:22 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4gnmo3$rvk@news.halcyon.com>
  8. References: <4gfocl$3do@thorn.cc.usm.edu>
  9. NNTP-Posting-Host: blv-pm11-ip3.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12.     Flames?  Probably not; most people on newsgroups are happy to answer
  13. questions.  Be on the lookout for newsgroup items talking about the
  14. FAQ (frequently asked questions), however, and down load that.
  15.  
  16. 1)  A heap is a pool of memory.  Windows 3.1 made a local heap (within
  17. the app's DS) and a global heap, the former faster but small, the
  18. latter larger but more overhead.  Win32 gives each process one heap by
  19. default, but the process can allocate other heaps, usually because the
  20. programer wants to do custom memory management for faster or more
  21. diagnostic allocations.  Win32 also allows you to create heaps that
  22. serialize access, i.e., two threads cannot bang against the heap
  23. simultaneously.
  24.  
  25. 2)  A virtual function cannot be resolved at compile time.  
  26. This is connected with a topic called polymorphism: if you derive a
  27. bunch of classes from a base class, CBase, and you give this base
  28. class a set of virtual functions, then you can pass pointers or
  29. references (but not instances) of the derived classes about as if they
  30. were CBase references, but you still call the derived class functions.
  31.  
  32. class CBase {
  33.     virtual void print( void ) const
  34.     {   cout << "I'm a CBase\n";  }
  35. };
  36.  
  37. class CDerived {
  38.     virtual void print( void ) const
  39.     {  cout << "I'm a CDerived\n"; }
  40. };
  41.  
  42. void Func1( CBase &   anObj )
  43. {
  44.     anObj.print();
  45. }
  46.  
  47. CDerived   myDer;
  48. CBase       myBase;
  49.  
  50. Func1( myDer );
  51. Fun1( myBase );
  52.  
  53. output:    "I'm a CDerived"
  54.         "I'm a CBase"
  55.  
  56. This is very, very useful and powerful and is at the heart of 
  57. information hiding strategies that allow big projects to be developed
  58. without interdependencies, etc.  
  59.  
  60. 3)  To tell the compiler how to do something differently.
  61. #ifdef _DEBUG tells the compiler to compile all code following until a
  62. #endif is encountered.  You can thus optionaly define _DEBUG on the
  63. compiler command-line and generate a slow diagnostic build during
  64. development, then not define _DEBUG to generate smaller, faster code
  65. for release.
  66.  
  67. #pragma pack(2)  wlll tell the compiler to align structure or class
  68. member variables on two-byte boundaries for all structures following
  69. the pragma up until another #pragma pack() is encountered.  Maybe the
  70. compiler was set to pack structures on 4- or 8-byte boundaries by
  71. default, but you need to maintain compatibility with another
  72. application's data for some of your structures.
  73.  
  74. 4) Overloading means that you can specifiy a different behavior for
  75. something based on the context in which it appears.
  76.  
  77. class X {
  78.      void Show( );     // show to the screen be default
  79.      void Show( HDC hDC )   // show to some other device, printer?
  80.      void Show( HMETAFILE hM ) // show yet somewhere else
  81. }
  82.  
  83. Overloading operators is convenient.  A string might overload
  84. operator+(CString  toAppend) to append another stirng to itself.
  85.  
  86. 5)  Run-time means when the program runs, instead of when it compiles.
  87. In 2) above, Func1( CBase & anObj ) could only resolve which print()
  88. method to call at runtime.  
  89.  
  90. 6)  Um, there are as many as you define, certainly.
  91.      By types of classes you mean like templates (aka parameterized
  92. classes), single-inheritence, multiple-inheritnece,
  93. multiple-virtual-inheritence, etc.? 
  94.  
  95. Hope this helps.
  96.                     --Norm
  97.  
  98.  
  99. afalgout@ocean.st.usm.edu (Andrew Wilson Falgout) wrote:
  100.  
  101. >Ok here it goes.  I know I'll probably receive a few flames from showing 
  102. >my lack of knowledge but I need answers.
  103. >1> What is the Heap exactly?  Is it similar to a stack? Or is it just 
  104. >   another word for a pool of memory.
  105. >2> What is the difference between a virtual function and a normal function.
  106. >3> What is the purpose of precompiler directives? An example would 
  107. >   probably help me understand this one better.
  108. >4> Is there an easy way to explain Overloading things?  Like Overloading 
  109. >   an Operator.
  110. >5> What is run-time?
  111. >6> How many different type/kinds of classes are there.  And what's the 
  112. >   difference between them?
  113. >   There are many more questions that come to mind but I really don't 
  114. >wish to take up anymore of everyone's time right now.  Thank you for 
  115. >whatever help I get.  And please don't flame a person who wants to learn.
  116.  
  117. >Thanks,
  118. >Andrew Falgout
  119.  
  120. >-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-
  121. >   "And remember, No matter where you go.  There you are."
  122. >   Andrew Wilson Falgout
  123. >       AKA: Kodos, Terok, Sabrina, and Gallus
  124. >-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-   
  125.  
  126.  
  127.